package com.twu.biblioteca.controllers;

import com.twu.biblioteca.models.LoginCredentials;
import com.twu.biblioteca.models.User;

/**
 * Created with IntelliJ IDEA.
 * User: mmoise
 * Date: 21/05/2013
 * Time: 12:03
 * To change this template use File | Settings | File Templates.
 */
public class UserController {
    private User[] users;

    public UserController(){

        User user1 = new User("111-1111","pass","Mircea","mircea@tw.com", "0722");
        users = new User[1];
        users[0] = user1;

    }

    public boolean validate(LoginCredentials credentials){
        return getUserWithCredentials(credentials)!=null;
    }

    public User getUserWithCredentials(LoginCredentials credentials) {
        User user = null;
        for (int i = 0; i<users.length; i++){
            if (users[i].credentials.equals(credentials)) { user = users[i]; break; }
        }

        return user;
    }
}
